package cn.calm.bundle;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import cn.calm.bundle.dao.IBundleDao;
import cn.calm.bundle.dao.impl.BundleDaoImpl;
import cn.calm.bundle.entity.Bundle;
import cn.calm.bundle.service.IBundleService;
import cn.calm.bundle.service.impl.BundleServiceImpl;

public class Activator implements BundleActivator {
	public static BundleContext context;

	@Override
	public void start(BundleContext arg0) throws Exception {
		context = arg0;
		IBundleService<Bundle> bundleService=new BundleServiceImpl<Bundle>();
//		ServiceReference<IBaseDao> serviceRef=	arg0.getServiceReference(IBaseDao.class);
		IBundleDao dao=new BundleDaoImpl();
		bundleService.setBaseDao(dao);
		EntityManager em = Persistence.createEntityManagerFactory("bundle")
				.createEntityManager();
		dao.setSession(em);
		arg0.registerService(IBundleService.class.getName(), bundleService, null);
	}

	@Override
	public void stop(BundleContext arg0) throws Exception {

	}

}
